#include <cstdio>
#include <cstring>

const int maxn = 110;

int main() {
	char id[18];
	int weight[20] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10,5, 8, 4, 2};
	const int mod = 11;
	char z2m[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
	int n;
	bool flag = true;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", id);
		int sum = 0;
		int j = 0;
		for (j = 0; j < 17; j++) {
			if (id[j] < '0' || id[j] > '9') break;
			sum += (id[j] - '0') * weight[j];
		}
		if (j < 17) {
			flag = false;
			printf("%s\n", id);
		} else {
			if (z2m[sum % mod] != id[17]) {
				flag = false;
				printf("%s\n", id);
			}
		}
	}

	if (flag)
		printf("All passed");

	return 0;
}
